<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-user-edit" th:object="${user}">
			<input name="userId"  type="hidden"  th:field="*{userId}" />
<!-- 			<div class="form-group">
				<label class="col-sm-3 control-label ">登录名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" readonly="true" th:field="*{loginName}"/>
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label">所属部门：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" readonly th:field="*{dept.deptName}">
				</div>
			</div>

			<div class="form-group" hidden="hidden">
				<label class="col-sm-3 control-label"></label>
				<div class="col-sm-8">
					<input class="form-control" type="hidden" name="nationId" th:field="*{nation}" id="nationId" th:value="*{nation}">
				</div>
			</div>

			<div class="form-group" hidden="hidden">
				<label class="col-sm-3 control-label"></label>
				<div class="col-sm-8">
					<input class="form-control" type="hidden" name="level" th:field="*{educationLevel}" id="level" th:value="*{educationLevel}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">姓名：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" readonly name="userName" id="userName" th:field="*{userName}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">身份证号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" readonly name="idCardNo" id="idCardNo" th:field="*{idCardNo}">
				</div>
			</div>
			<div class="form-group">
			<label class="col-sm-3 control-label">民族：</label>
			<div class="col-sm-8">
				<select class="select2 select2-nation form-control" id="nation" name="nation">
				</select>
			</div>
		</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">籍贯：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="nativePlace" id="nativePlace"  th:field="*{nativePlace}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">文化程度：</label>
				<div class="col-sm-8">
				<select class="select2 select2-educationLevel form-control" id="educationLevel" name="educationLevel"  th:text="*{educationLevel}" >
				</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">加入群团时间：</label>
				<div class="col-sm-8">
					<input id="joinTime" placeholder="" name="joinTimes" class="form-control valid" type="text" aria-required="true" aria-invalid="false">
				</div>
			</div>
<!-- 			<div class="form-group">
				<label class="col-sm-3 control-label">职务：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="position" id="position" th:field="*{position}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">政治面貌：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="political" id="political" th:field="*{political}">
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="email" th:field="*{email}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">手机：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="phonenumber" id="phonenumber" th:field="*{phonenumber}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">性别：</label>
				<div class="col-sm-8">
					<div class="radio radio-info radio-inline">
						<input type="radio" id="radio1" th:field="*{sex}" name="sex" value="0">
						<label for="radio1">男</label>
					</div>
					<div class="radio radio-danger radio-inline">
						<input type="radio" id="radio2" th:field="*{sex}" name="sex" value="1">
						<label for="radio2">女</label>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">个人简介：</label>
				<div class="col-sm-8">
					<textarea rows="5" cols="1" class="form-control" name="introduce" id="introduce"></textarea>
				</div>
			</div>
			
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:inline="javascript">
		//格式化时间
		var joinTime = [[${user.joinTime}]];
		if(joinTime != null){
			$("#joinTime").attr("value", joinTime.substring(0, 10));
		}
		
		
		//格式化数据赋值富文本框
		var introduce = [[${user.introduce}]];
		$("#introduce").val(introduce);

        var education = [{ id: 0, text: '中专' },{ id: 1, text: '大专' },{ id: 2, text: '本科' },{ id: 3, text: '硕士研究生' },{ id: 4, text: '博士生' }];
        $(".select2-educationLevel").select2({
            placeholder:"请选择文化程度",
            language: "zh-CN",
            data: education,
           // maxSelection: 3,//设置可以选择的项的限制

        });
        var levelId = $('#level').val();
        $("#educationLevel").select2().val(levelId).trigger("change");

        var nation = [{ id: 0, text: '壮族' },{ id: 1, text: '汉族' },{ id: 2, text: '满族' },{ id: 3, text: '回族' },{ id: 4, text: '苗族' },{ id: 5, text: '维吾尔族' },
            { id: 6, text: '土家族' },{ id: 7, text: '彝族' },{ id: 8, text: '蒙古族' },{ id: 9, text: '藏族' },{ id: 10, text: '布依族' },{ id: 11, text: '藏侗族族' },
            { id: 12, text: '瑶族' },{ id: 13, text: '朝鲜族' },{ id: 14, text: '白族' },{ id: 15, text: '哈尼族' },{ id: 16, text: '哈萨克族' },{ id: 17, text: '黎族' },
            { id: 18, text: '傣族' },{ id: 19, text: '畲族' },{ id: 20, text: '傈僳族' },{ id: 21, text: '仡佬族' },{ id: 22, text: '东乡族' },{ id: 23, text: '高山族' },
            { id: 24, text: '拉祜族' },{ id: 25, text: '水族' },{ id: 26, text: '佤族' },{ id: 27, text: '纳西族' },{ id: 28, text: '羌族' },{ id: 29, text: '土族' },
            { id: 30, text: '仫佬族' },{ id: 31, text: '锡伯族' },{ id: 32, text: '柯尔克孜族' },{ id: 33, text: '达斡尔族' },{ id: 34, text: '景颇族' },{ id: 35, text: '毛南族' },
            { id: 36, text: '撒拉族' },{ id: 37, text: '布朗族' },{ id: 38, text: '塔吉克族' },{ id: 39, text: '阿昌族' },{ id: 40, text: '普米族' },{ id: 41, text: '鄂温克族' },
            { id: 42, text: '怒族' },{ id: 43, text: '京族' },{ id: 44, text: '基诺族' },{ id: 45, text: '德昂族' },{ id: 46, text: '保安族' },{ id: 47, text: '俄罗斯族' },
            { id: 48, text: '裕固族' },{ id: 49, text: '乌孜别克族' },{ id: 50, text: '门巴族' },{ id: 51, text: '鄂伦春族' },{ id: 52, text: '独龙族' },{ id: 53, text: '塔塔尔族' },
            { id: 54, text: '赫哲族' },{ id: 55, text: '珞巴族' }];
        $(".select2-nation").select2({
            placeholder:"请选择民族",
            language: "zh-CN",
            data: nation,
            multiple:false,
			allowClear:true
            // maxSelection: 3,//设置可以选择的项的限制
        });

        var nationId = $('#nationId').val();

        $("#nation").select2().val(nationId).trigger("change");
        
        //时间选择初始化
        $("#joinTime").datepicker({
            format: 'yyyy-mm-dd',
            language: 'cn',
        });

       /*  $('#introduce').summernote({
            lang: 'zh-CN',
            height: 100
        }); */

		$("#form-user-edit").validate({
			rules:{
				userName:{
					required:true,
				},
				nativePlace:{
					required:true
				},
				joinTime:{
					required:true
				},
				educationLevel:{
					required:true
				},
				email:{
					required:true,
		            email:true,
		            remote: {
		                url: ctx + "system/user/checkEmailUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"userId": function() {
		                        return $("input[name='userId']").val();
		                    },
		        			"email": function() {
		                        return $("input[name='email']").val();
		                    }
		                },
		                dataFilter: function (data, type) {
		                    if (data == "0") return true;
		                    else return false;
		                }
		            }
				},
				phonenumber:{
					required:true,
					isPhone:true,
		            remote: {
		                url: ctx + "system/user/checkPhoneUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"userId": function(){
		                        return $("input[name='userId']").val();
		                    },
		        			"phonenumber": function() {
		                        return $("input[name='phonenumber']").val();
		                    }
		                },
		                dataFilter: function (data, type) {
		                    if (data == "0") return true;
		                    else return false;
		                }
		            }
				},
			},
			messages: {
				"email": {
		            remote: "Email已经存在"
		        },
				"phonenumber":{
		        	remote: "手机号码已经存在"
				}
		    },
			submitHandler:function(form){
				var forms = new FormData(document.getElementById('form-user-edit'));
				$.modal.loading("正在处理中，请稍后...");
					$.ajax({
						url : ctx + "system/user/profile/update",
						type : "post",
						dataType : "json",
						data : forms,
						processData: false,
						contentType: false,
						success : function(result) {
							$.operate.saveSuccess(result)
						},
						error: function(){
							$.modal.msgError("请求失败");
						}
					});
			}
		});

	</script>
</body>
</html>
